{% extends "main/base.html" %}
{% load i18n main_tag %}
{% block title %}{% trans '设备详情' %}{% endblock %}
{% block content %}
<div class="row">
    <aside class="profile-nav col-lg-3">
        <section class="panel">
            <div class="user-heading round">
                <h1>{{ object.equipment_code }}</h1>
                {% if perms.main.view_equipment_basic_price %}<p>{{ object.basic_price }} CNY</p>{% endif %}
            </div>
            <ul class="nav nav-pills nav-stacked">
                <li><a href=""> <i class="fa fa-gear"></i> {% trans '设备详情' %} </a></li>
                <li><a href="{% url 'main:equipment_detail_public' object.pk %}" target="_blank"> <i class="fa fa-star"></i> {% trans '设备详情' %} </a></li>
                <!--<li><a href=""> <i class="fa fa-calendar"></i> {% trans '销售记录' %} <span class="label label-danger pull-right r-activity">{{ object.order_count }}</span></a></li>-->
                {% if perms.main.change_equipment %}{% if object %}<li><a href="{% url 'main:equipment_update' object.pk %}"> <i class="fa fa-edit"></i> {% trans '编辑资料' %}  </a></li>{% endif %}{% endif %}
                {% if perms.main.change_equipment %}{% if object %}<li><a href="{% url 'main:equipment_copy' object.pk %}"> <i class="fa fa-copy"></i> {% trans "复制设备" %} </a></li>{% endif %}{% endif %}
                {% if perms.main.add_equipmentassembly %}{% if object %}<li><a href="{% url 'main:equipment_als_create' %}?e_pk={{ object.pk }}"> <i class="fa fa-sitemap"></i> {% trans "新建组装" %} </a></li>{% endif %}{% endif %}
            </ul>
        </section>
        <section class="panel">
            <header class="panel-heading">
                {% trans '附件' %}
            </header>
            <div class="list-group">
                {% if object.drawing_cn %}
                <a class="list-group-item" href="{{ object.drawing_cn|qiniu }}">{% trans '中文图纸' %}</a>
                {% endif %}{% if object.drawing_en %}
                <a class="list-group-item" href="{{ object.drawing_en|qiniu }}">{% trans '英文图纸' %}</a>
                {% endif %}{% if object.file_cn %}
                <a class="list-group-item" href="{{ object.file_cn|qiniu }}">{% trans '中文资料' %}</a>
                {% endif %}{% if object.file_en %}
                <a class="list-group-item" href="{{ object.file_en|qiniu }}">{% trans '英文资料' %}</a>
                {% endif %}{% if object.file_3d %}
                <a class="list-group-item" href="{{ object.file_3d|qiniu }}">{% trans '3D图纸' %}</a>
                {% endif %}{% if object.equipment_img %}
                <a class="list-group-item" href="{{ object.equipment_img|qiniu }}">{% trans '设备图片' %}</a>
                {% endif %}
            </div>
        </section>
    </aside>
    <aside class="profile-info col-lg-9">
        <section class="panel">
            <div class="panel-heading">
                <h4 class="heading">{% trans '英文名' %}: {{ object.equipment_en|default_if_none:'N/A' }}</h4>
                <h4 class="heading">{% trans '中文名' %}: {{ object.equipment_cn|default_if_none:'N/A' }}</h4>
                <h4 class="heading">{% trans '产品编号' %}: {{ object.equipment_code_auto }}</h4>
            </div>
            <div class="panel-body bio-graph-info">
                <div class="row">
                    <div class="bio-row">
                        <p><span>{% trans '设备类型' %}: </span><a href="{% url 'main:equipment_list' %}?c={{ object.equipment_type.id }}">{{ object.equipment_type.equipment_type_cn }}</a></p>
                    </div>
                    <div class="bio-row">
                        <p><span>{% trans '设备单位' %}: </span>{{ object.equipment_unit.equipment_unit_cn }}</p>
                    </div>
                    {% if object.size_para %}
                    <div class="bio-row">
                        <p><span>{% trans '设备尺寸' %}: </span>{{ object.size_para }}</p>
                    </div>
                    {% endif %}
                    {% if object.weight %}
                    <div class="bio-row">
                        <p><span>{% trans '设备总量' %}: </span>{{ object.weight }} kg</p>
                    </div>
                    {% endif %}
                    {% if object.power %}
                    <div class="bio-row">
                        <p><span>{% trans '设备功率' %}: </span>{{ object.power }} kw</p>
                    </div>
                    {% endif %}
                    {% if object.power_type %}
                    <div class="bio-row">
                        <p><span>{% trans '设备电源' %}: </span>{{ object.power_type }}</p>
                    </div>
                    {% endif %}
                    {% if object.equipment_exp_code %}
                    <div class="bio-row">
                        <p><span>{% trans '设备海关编码' %}: </span>{{ object.equipment_exp_code }}</p>
                    </div>
                    {% endif %}
                    {% if object.amount_left %}
                    <div class="bio-row">
                        <p><span>{% trans '库存' %}: </span>{{ object.amount_left }}</p>
                    </div>
                    {% endif %}
                </div>
            </div>
        </section>
        <section>
            <div class="row">

            </div>
        </section>
        <section class="panel">
            <header class="panel-heading tab-bg-dark-navy-blue ">
                <ul class="nav nav-tabs">
                    <li class="active">
                        <a data-toggle="tab" href="#equipment_para_cn" aria-expanded="true">{% trans '中文介绍' %}</a>
                    </li>
                    <li class="">
                        <a data-toggle="tab" href="#equipment_para_en" aria-expanded="false">{% trans '英文介绍' %}</a>
                    </li>
                    <li class="">
                        <a data-toggle="tab" href="#sale_info" aria-expanded="false">{% trans '关联订单' %}<span class="badge bg-important">{{ object.order_count }}</span></a>
                    </li>
                    <li class="">
                        <a data-toggle="tab" href="#assemly" aria-expanded="false">{% trans '设备组装' %}<span class="badge bg-warning">{{ object.assembly_count }}</span></a>
                    </li>
                    <li class="">
                        <a data-toggle="tab" href="#other_info" aria-expanded="false">{% trans '其他资料' %}</a>
                    </li>
                </ul>
            </header>
            <div class="panel-body">
                <div class="tab-content">
                    <div id="equipment_para_cn" class="tab-pane active">
                        {{ object.equipment_para_cn|default_if_none:'N/A'|safe|linebreaks }}
                    </div>
                    <div id="equipment_para_en" class="tab-pane">
                        {{ object.equipment_para_en|default_if_none:'N/A'|safe|linebreaks }}
                    </div>
                    <div id="sale_info" class="tab-pane">
                        {% if object.related_orders %}{% for od in object.related_orders %}
                            <div class="col-lg-6">
                                <div class="alert alert-success">
                                    {% if od.order.created_by_id == request.user.pk or request.user.pk in od.order.cooperators or request.user.is_staff or perms.main.view_all_orders or od.order.order_state.pk == 2 %}
                                    <a href="{% url 'main:order_detail' od.order.pk %}"><h4>{{ od.order.order_code }}</h4></a>
                                    {% else %}
                                    <h4>{{ od.order.order_code }}</h4>
                                    {% endif %}
                                    <p>{% trans '订单描述' %}: {{ od.order.order_desc }}</p>
                                    <p>{% trans '订单状态' %}: {{ od.order.order_state }}</p>
                                    <p>{% trans '关联销售' %}: {{ od.order.salesman }}</p>
                                    <p>{% trans '订单日期' %}: {{ od.order.datetime_created|date:"Y-m-d" }}</p>
                                    {% if perms.main.view_equipment_basic_price %}<p>{% trans '订单金额' %}: {{ od.order.price_with_tax }} 元</p>{% endif %}
                                </div>
                            </div>
                        {% endfor %}{% endif %}
                    </div>
                    <div id="assemly" class="tab-pane">
                        {% if object.related_assemblies %}{% for a_s in object.related_assemblies %}
                        {% if a_s.created_by_id == request.user.pk or request.user.pk in a_s.cooperators or request.user.is_staff %}
                            <div class="col-lg-12">
                                <div class="alert alert-danger">
                                    <a href="{% url 'main:equipment_assembly_detail' a_s.pk %}"><h4>{{ a_s.assembly_name }}</h4></a>
                                    <p>{% trans '备注' %}: {{ a_s.notes }}</p>
                                    {% if a_s.assembly_list %}
                                    <div class="alert alert-success">
                                        {% for ai in a_s.assembly_list %}
                                            {{ ai }}
                                            {% if perms.main.view_equipment_basic_price %}= ¥ {{ ai.total_value|default_if_none:'N/A' }}{% endif %}
                                            <br>
                                        {% endfor %}
                                    </div>
                                    {% endif %}
                                    {% if perms.main.view_equipment_basic_price %}<p>{% trans '成本' %}: {{ a_s.total_value }} 元</p>{% endif %}
                                </div>
                            </div>
                        {% endif %}
                        {% endfor %}{% endif %}
                    </div>
                    <div id="other_info" class="tab-pane">
                        {% if perms.main.view_equipment_basic_price %}
                        {% trans '市场价' %}: {{ object.basic_price }}元<br>{% endif %}{% if perms.main.view_equipment_dist_price %}
                        {% trans '工厂底价' %}: {{ object.dist_price }}元{% endif %}<br>{% if perms.main.change_equipment_price %}
                        <br><a class="btn btn-info" href="{% url 'main:equipment_price_update' object.pk %}">{% trans "更新价格" %}</a>{% endif %}
                    </div>
                </div>
            </div>
        </section>
    </aside>
</div>
{% endblock %}